<template>
  <div class="article-container">
    <!-- 加载状态 -->
    <el-skeleton v-if="data.loading" :rows="8" animated class="skeleton-container" />
    
    <!-- 文章内容 -->
    <div v-else class="article-content">
      <!-- 文章头部 -->
      <div class="article-header">
        <div class="header-overlay"></div>
        <div 
          class="header-background"
          :style="{ backgroundImage: `url(${data.detailAricle[0].postlink})` }"
        ></div>
        
        <div class="header-content">
          <!-- 标签区域 -->
          <div class="article-tags">
            <el-tag 
              type="info" 
              effect="plain" 
              round 
              size="large"
              class="tag-item"
            >
              {{ data.detailAricle[0].keywords }}
            </el-tag>
            <el-tag 
              type="primary" 
              effect="plain" 
              round 
              size="large"
              class="tag-item"
            >
              {{ data.detailAricle[0].articleType.name }}
            </el-tag>
          </div>
          
          <!-- 文章标题 -->
          <h1 class="article-title">
            {{ data.detailAricle[0].title }}
          </h1>
          
          <!-- 作者信息 -->
          <div class="author-info">
            <el-avatar 
              :src="data.detailAricle[0].userInfo.avatar" 
              :size="40"
              class="author-avatar"
            />
            <div class="author-details">
              <span class="author-name">{{ data.detailAricle[0].userInfo.user.name }}</span>
              <div class="publish-info">
                <el-icon class="date-icon"><Calendar /></el-icon>
                <span class="publish-date">
                  {{ dayjs(data.detailAricle[0].createdAt).format('YYYY年MM月DD日') }}
                </span>
              </div>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 文章主体 -->
      <div class="article-main">
        <el-container>
          <el-main class="main-content">
            <!-- 文章正文 -->
            <el-card class="content-card" shadow="never">
              <div 
                class="article-text braft-output-content"
                v-html="data.detailAricle[0].context"
              ></div>
            </el-card>
            

          </el-main>
        </el-container>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, onUpdated } from 'vue'
import axios from '../../utils/Axios'
import base from '../../api/base'
import { useRoute } from 'vue-router'
import dayjs from 'dayjs'
import router from '../../router'
import { TweenMax, Back } from 'gsap'
import { Calendar, Star, View } from '@element-plus/icons-vue'

const route = useRoute()
const data = reactive({
  detailAricle: [],
  recommends: [],
  loading: true,
})
axios(base.getArticleInfo + `/${route.query.id}`).then(res => {
  data.detailAricle = res.data.detailArticle
  data.recommends = res.data.recommends
  data.loading = false
})

onUpdated(() => {
  let objects = [
    '.articleInfo-header-info-label',
    '.articleInfo-header-info-title',
    '.articleInfo-header-info-user',
  ]
  TweenMax.staggerFrom(objects, 1, { y: '+=100', ease: Back.easeOut }, 0.2)
})

function goDerails(num) {
  router.push({ path: '/articleDetails', query: { id: num } })
}
</script>
<style scoped lang="less">
/* 全局样式重置 */
::v-deep .media-wrap img,
::v-deep .media-wrap video {
  width: 100% !important;
  height: 100% !important;
}

/* 主容器 */
.article-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  font-family: 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
}

/* 骨架屏样式 */
.skeleton-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px;
}

/* 文章内容容器 */
.article-content {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  background: #ffffff;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  border-radius: 16px;
  overflow: hidden;
}

/* 文章头部 */
.article-header {
  position: relative;
  height: 500px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  
  @media (max-width: 768px) {
    height: 400px;
  }
  
  @media (max-width: 480px) {
    height: 300px;
  }
}

.header-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  filter: blur(2px);
  transform: scale(1.1);
}

.header-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    135deg,
    rgba(0, 0, 0, 0.6) 0%,
    rgba(0, 0, 0, 0.3) 50%,
    rgba(0, 0, 0, 0.6) 100%
  );
  z-index: 1;
}

.header-content {
  position: relative;
  z-index: 2;
  width: 90%;
  max-width: 800px;
  text-align: center;
  color: white;
  padding: 0 20px;
}

/* 标签样式 */
.article-tags {
  margin-bottom: 24px;
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.tag-item {
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.2) !important;
  border: 1px solid rgba(255, 255, 255, 0.3) !important;
  color: white !important;
  font-weight: 500;
  padding: 8px 16px;
  transition: all 0.3s ease;
  
  &:hover {
    background: rgba(255, 255, 255, 0.3) !important;
    transform: translateY(-2px);
  }
}

/* 文章标题 */
.article-title {
  font-size: 3.5rem;
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 32px 0;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
  letter-spacing: -0.02em;
  
  @media (max-width: 768px) {
    font-size: 2.5rem;
  }
  
  @media (max-width: 480px) {
    font-size: 2rem;
  }
}

/* 作者信息 */
.author-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.1);
  padding: 16px 24px;
  border-radius: 50px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  max-width: fit-content;
  margin: 0 auto;
}

.author-avatar {
  border: 3px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.author-details {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.author-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: white;
}

.publish-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.8);
}

.date-icon {
  font-size: 14px;
}

/* 文章主体 */
.article-main {
  background: #ffffff;
}

.main-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 60px 20px;
}

/* 内容卡片 */
.content-card {
  margin-bottom: 60px;
  border: none;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.article-text {
  font-size: 1.1rem;
  line-height: 1.8;
  color: #2c3e50;
  
  ::v-deep {
    h1, h2, h3, h4, h5, h6 {
      color: #1a202c;
      margin: 2em 0 1em 0;
      font-weight: 600;
    }
    
    p {
      margin: 1.5em 0;
      text-align: justify;
    }
    
    img {
      max-width: 100%;
      height: auto;
      border-radius: 8px;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
      margin: 2em 0;
    }
    
    blockquote {
      border-left: 4px solid #409eff;
      background: #f8f9fa;
      padding: 16px 20px;
      margin: 2em 0;
      border-radius: 0 8px 8px 0;
    }
    
    code {
      background: #f1f2f6;
      padding: 2px 6px;
      border-radius: 4px;
      font-family: 'Monaco', 'Consolas', monospace;
    }
  }
}



/* 响应式设计 */
@media (max-width: 768px) {
  .article-content {
    margin: 0;
    border-radius: 0;
  }
  
  .main-content {
    padding: 40px 16px;
  }
  
  .header-content {
    width: 95%;
  }
  
  .author-info {
    flex-direction: column;
    text-align: center;
    padding: 20px;
  }
  
  .author-details {
    align-items: center;
  }
}

@media (max-width: 480px) {
  .article-tags {
    gap: 8px;
  }
  
  .tag-item {
    padding: 6px 12px;
    font-size: 0.9rem;
  }
  
  .main-content {
    padding: 30px 12px;
  }
  
  .recommend-image-container {
    height: 160px;
  }
}
</style>
